


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelDirecorio.java
 *
 * Created on 11/01/2012, 05:46:27 PM
 */
package co.edu.eam.clinica.vista.gui.paciente;

import co.edu.eam.clinica.vista.controladores.paciente.controladorPanelDirecorio;
import co.edu.eam.clinica.vista.gui.common.PanelOncologos;
import co.edu.eam.clinica.vista.gui.common.VentanaPrincipalManager;
import co.edu.eam.persitencia.entidades.Paciente;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Camilo Andres
 */
public class PanelDirecorio extends PanelOncologos{

//    
    controladorPanelDirecorio mid;
    
    public PanelDirecorio() {
      
        initComponents();
        

//
    }
//
//    /** This method is called from within the constructor to
//     * initialize the form.
//     * WARNING: Do NOT modify this code. The content of this method is
//     * always regenerated by the Form Editor.
//     */
//    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tablaPersonas = new javax.swing.JTable();
        bttnLLenarPaciente = new javax.swing.JButton();
        bttnverPaciente = new javax.swing.JButton();

        tablaPersonas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Documento", "Nombre", "Apellido", "e-mail"
            }
        ));
        jScrollPane1.setViewportView(tablaPersonas);

        bttnLLenarPaciente.setText("Llenar");
        bttnLLenarPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttnLLenarPacienteActionPerformed(evt);
            }
        });

        bttnverPaciente.setText("Ver");
        bttnverPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttnverPacienteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(bttnLLenarPaciente)
                        .addGap(32, 32, 32)
                        .addComponent(bttnverPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bttnLLenarPaciente)
                    .addComponent(bttnverPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(15, 15, 15))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void bttnLLenarPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttnLLenarPacienteActionPerformed
        try {
            List<Paciente> pa=mid.listarTodosPacientes();
            
            DefaultTableModel tabla=(DefaultTableModel) tablaPersonas.getModel();
            tabla.setRowCount(pa.size());
            
            for(int i=0;i<pa.size();i++){
               tabla.setValueAt(pa.get(i).getDocumento(), i, 0); 
               tabla.setValueAt(pa.get(i).getNombre(), i, 1); 
               tabla.setValueAt(pa.get(i).getPrimerApellido(), i, 2); 
               tabla.setValueAt(pa.get(i).getEmail(), i, 3); 
                
                
            }

         
            
            
    //        ventana.agregarPanel(new PanelCrearPaciente(documento, ventana));
    //        
        } catch (Exception ex) {
            Logger.getLogger(PanelDirecorio.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_bttnLLenarPacienteActionPerformed

    private void bttnverPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttnverPacienteActionPerformed
        // TODO add your handling code here:}
        
        DefaultTableModel modelo = (DefaultTableModel) tablaPersonas.getModel();
        int id = tablaPersonas.getSelectedRow();
        String documento =  (String) tablaPersonas.getValueAt(id, 0);

        try {
         PanelCrearPaciente   panel = new PanelCrearPaciente(documento);
        VentanaPrincipalManager.agregarVentana(panel);
        } catch (Exception ex) {
            Logger.getLogger(PanelDirecorio.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        this.tablaPersonas.setModel(modelo);
        
        
    }//GEN-LAST:event_bttnverPacienteActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bttnLLenarPaciente;
    private javax.swing.JButton bttnverPaciente;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tablaPersonas;
    // End of variables declaration//GEN-END:variables
}
